package com.jyw.web.controller.system;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import com.jyw.system.domain.dto.SysDeptPhoneBookBatchAddDto;
import com.jyw.system.domain.dto.SysDeptPhoneBookEditDto;
import com.jyw.system.domain.dto.SysDeptPhoneBookPageDto;
import com.jyw.system.domain.dto.SysDeptPhoneBookSaveDto;
import com.jyw.system.domain.vo.SysDeptIpAddressVo;
import com.jyw.system.domain.vo.SysDeptPhoneBookVo;
import com.jyw.system.service.ISysDeptPhoneBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 科室电话薄Controller
 *
 * @author zhangcheng
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/system/phoneBook")
@Api(tags = "系统科室电话薄")
public class SysDeptPhoneBookController extends BaseController {
    @Resource
    private ISysDeptPhoneBookService sysDeptPhoneBookService;

    /**
     * 查询科室电话薄列表
     */
    @GetMapping("/list")
    @ApiOperation("查询科室电话薄列表")
    public TableDataInfo<SysDeptPhoneBookVo> list(SysDeptPhoneBookPageDto pageDto) {
        startPage();
        List<SysDeptPhoneBookVo> bookList = sysDeptPhoneBookService.getBookList(pageDto);
        return getDataTable(bookList);
    }

    /**
     * 根据电话查询报修科室
     */
    @GetMapping(value = "/getDeptByPhone")
    @ApiOperation("根据电话查询报修科室")
    public CommonResult<SysDeptPhoneBookVo> getDeptByPhone(String phone) {
        return CommonResult.success(sysDeptPhoneBookService.getDeptByPhone(phone));
    }


    /**
     * 获取科室电话薄详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取科室电话薄详细信息")
    public CommonResult<SysDeptPhoneBookVo> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(sysDeptPhoneBookService.getInfoById(id));
    }

    /**
     * 新增或修改科室电话薄
     */
    @ApiOperation("新增或修改科室电话薄")
    @Log(title = "新增或修改科室电话薄", businessType = BusinessType.INSERT)
    @PostMapping(value = "sysSave")
    public CommonResult sysSave(@RequestBody @Valid SysDeptPhoneBookSaveDto saveDto) {
        sysDeptPhoneBookService.sysSave(saveDto);
        return CommonResult.success();
    }

    /**
     * 新增科室电话薄
     */
    @ApiOperation("新增科室电话薄")
    @Log(title = "批量科室电话薄", businessType = BusinessType.INSERT)
    @PostMapping(value = "sysBatchAdd")
    @PreAuthorize("@ss.hasPermi('system:dept:phone:add')")
    public CommonResult add(@RequestBody @Valid SysDeptPhoneBookBatchAddDto batchAddDto) {
        sysDeptPhoneBookService.sysBatchAdd(batchAddDto);
        return CommonResult.success();
    }

    /**
     * 修改科室电话薄
     */
    @ApiOperation("修改科室电话薄")
    @Log(title = "科室电话薄", businessType = BusinessType.UPDATE)
    @PutMapping(value = "sysEdit")
    @PreAuthorize("@ss.hasPermi('system:dept:phone:edit')")
    public CommonResult edit(@RequestBody @Valid SysDeptPhoneBookEditDto editDto) {
        sysDeptPhoneBookService.sysEdit(editDto);
        return CommonResult.success();
    }

    /**
     * 删除科室电话薄
     */
    @ApiOperation("删除科室电话薄")
    @Log(title = "科室电话薄", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPermi('system:dept:phone:remove')")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(sysDeptPhoneBookService.deleteByIds(ids));
    }
}
